package org.zhxy.zhxy.controller.front;



import org.apache.poi.openxml4j.opc.OPCPackage;
import org.zhxy.zhxy.entity.User;
import org.zhxy.zhxy.entity.dto.*;
import org.zhxy.zhxy.service.UserService;
import org.springframework.web.bind.annotation.*;
import org.zhxy.zhxy.utils.Result;
import org.zhxy.zhxy.utils.UserHolder;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.Map;

/**
 * 小程序用户表(User)表控制层
 *
 * @author yayong
 * @since 2024-10-19 21:53:20
 */
@RestController
@RequestMapping("/api/user")
public class UserController {

/**
 * 服务对象
 */
@Resource
private UserService userService;

  //用户注册

  @PostMapping("/register")
  public Result register(@RequestBody UserRegisterDto userRegisterDto){
      userService.register(userRegisterDto);
      return Result.success();
  }

    @PostMapping("/login")
    public Result login(@RequestBody UserLoginDto userLoginDto){
       String token =   userService.login(userLoginDto);
        return Result.success(token);
    }
    /**
     * 获取用户信息
     */
    @GetMapping("/get-user-info")
    public Result info(){
        User user = UserHolder.getUser();
        Integer id = user.getId();
        return Result.success(userService.getById(id));
    }

    //修改用户信息
    @PostMapping("/update")
    public Result updateUser(@RequestBody UserUpdateInfo updateInfo){

        userService.updateInfo(updateInfo);
        return Result.success();
    }

    /**
     * 修改密码
     */
    @PostMapping("/update-password")
    public Result updatePassword(@RequestBody UserUpdatePassWordDto userUpdatePassWordDto){
        userService.updatePassWord(userUpdatePassWordDto);
        return Result.success("修改密码成功");
    }

    /**
     * 换绑邮箱
     */
    @PostMapping("/update-email")
    public Result updateEmail(@RequestBody UserUpdateEmailDto userUpdateEmailDto){
        userService.updateEmail(userUpdateEmailDto);
        return Result.success("修改邮箱成功");
    }

    /**
     * 忘记密码
     */
    @PostMapping("/forget-password")
    public Result forgetPassword(@RequestBody UserFogetpassWordDto userForgetPasswordDto){
        userService.forgetPassword(userForgetPasswordDto);
        return Result.success("修改密码成功");
    }







}

